﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using Skyworth.CRM.Service.Entity;
using Skyworth.CRM.Service.IDAL;

namespace Skyworth.CRM.DAL
{
    public class CustCashDAL : SuperDataBase, ICustCashDAL
    {
        public CustCash GetCustomerCash(int custId)
        {
            CustCash model = null;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" select top 1 FCashAmount,FcreditAmount,FTotalAmount from T_Cash ");
            strSql.Append(" where Fcustid=@custId ");
            DbCommand cmd = DB.GetSqlStringCommand(strSql.ToString());
            DB.AddInParameter(cmd, "@custId", DbType.Int32, custId);
            using (IDataReader dr = DB.ExecuteReader(cmd))
            {
                while (dr.Read())
                {
                    model = new CustCash();

                    model.CustId = custId;
                    model.CashAmount = Convert.ToDecimal(dr["FCashAmount"].ToString());
                    model.CreditAmount = Convert.ToDecimal(dr["FcreditAmount"].ToString());
                    model.TotalAmount = Convert.ToDecimal(dr["FTotalAmount"].ToString());
                }
            }
            return model;
        }
    }
}
